import java.io.File;
import java.util.Vector;

//@author A0099655J
public class Storage {

	public String filename;
	Database DATABASE;
	Logger LOG;
	
	//@author A0099655J
	// Constructor
	public Storage(String DATAFILE_NAME, String LOGFILE_NAME) {
		
		DATABASE = new Database(DATAFILE_NAME);
		LOG = new Logger(LOGFILE_NAME);

		// assert statements to ensure relevant files are created
		assert (new File(DATAFILE_NAME).exists());
		assert (new File(LOGFILE_NAME).exists());
	}
	
	//@author A0099655J
	public void updateLocalFiles(Vector<Task> list, Vector<LogEntry> log) {
		writeDataToDisk(list);
		writeLogToDisk(log);
	}
	
	//@author A0099655J
	// Write updated Database of Tasks to disk storage
	public void writeDataToDisk(Vector<Task> contents) {
		DATABASE.write(contents);
	}

	//@author A0099655J
	// Write updated LogFile to disk storage
	public void writeLogToDisk(Vector<LogEntry> log) {
		LOG.write(log);
	}

	//@author A0099655J
	// Read Tasks already stored on disk storage
	public Vector<Task> loadDataFromDisk() {
		return DATABASE.read();
	}

	//@author A0099655J
	// Read log of previous operations stored on disk storage
	public Vector<LogEntry> loadLogFromDisk() {
		return LOG.read();
	}
}
